package com.leeyu.rabbitmq.listener;

import com.leeyu.rabbitmq.config.DeadLetterConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

//@Component
public class DeadListener {

    @RabbitListener(queues = DeadLetterConfig.NORMAL_QUEUE)
    public void consume(String msg, Channel channel, Message message) throws IOException {
        System.out.println("DeadListener 接收到Normal队列消息：" + msg);
        // 拒绝和nack都可以将消息放入死信队列，需要将requeue设置为false
        //channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
        channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
    }
}
